﻿namespace SenenFernandez.Sensktop.Configuration
{
    using SenenFernandez.SmartExtensionMethods;

    using System.Configuration;

    public class SensktopConfiguration : ConfigurationSection
    {
        /// <summary>
        /// Access Configuration.Instance to get the singleton object.
        /// Then call methods on that instance.
        /// </summary>
        public static SensktopConfiguration Instance
        {
            get { return ConfigurationManager.GetSection(DefaultValue.ConfigurationSection) as SensktopConfiguration ?? new SensktopConfiguration(); }
            set { ConfigurationManager.RefreshSection(DefaultValue.ConfigurationSection); }
        }

        /// <summary>
        /// Indicates the visibility of the Windows Desktop.
        /// </summary>
        [ConfigurationProperty("takeFullControl", DefaultValue = DefaultValue.TakeFullControl)]
        public bool TakeFullControl
        {
            get { return this["takeFullControl"].ToBool(DefaultValue.TakeFullControl); }
            set { this["takeFullControl"] = value; }
        }

        /// <summary>
        /// Indicates the Culture of the Application.
        /// </summary>
        [ConfigurationProperty("culture", DefaultValue = DefaultValue.Culture)]
        public string Culture
        {
            get { return this["culture"].ToString(); }
            set { this["culture"] = value; }
        }

        /// <summary>
        /// Indicates the main display.
        /// </summary>
        [ConfigurationProperty("displayName")]
        public string DisplayName
        {
            get { return this["displayName"].ToString(); }
            set { this["displayName"] = value; }
        }

        /// <summary>
        /// Indicates the Sensktop Height.
        /// </summary>
        [ConfigurationProperty("height", DefaultValue = DefaultValue.Height)]
        public double Height
        {
            get { return this["height"].ToDouble(DefaultValue.Height); }
            set { this["height"] = value; }
        }

        /// <summary>
        /// Indicates the file path to the menu items configuration.
        /// </summary>
        [ConfigurationProperty("menuSourcePath", DefaultValue = DefaultValue.MenuSourcePath)]
        public string MenuSourcePath
        {
            get { return this["menuSourcePath"].ToString(); }
            set { this["menuSourcePath"] = value; }
        }

        /// <summary>
        /// Indicates the time to check the processes.
        /// </summary>
        [ConfigurationProperty("refreshInterval", DefaultValue = DefaultValue.RefreshInterval)]
        public int RefreshInterval
        {
            get
            {
                int result = this["refreshInterval"].ToInt(DefaultValue.RefreshInterval);
                if (result < DefaultValue.MinRefreshInterval)
                {
                    result = DefaultValue.MinRefreshInterval;
                }
                return result;
            }
            set { this["refreshInterval"] = value; }
        }
    }
}